<template>
	<view class="main">
		<!-- 顶部栏 -->
		<MyHead :title="title"></MyHead>
		
		<!-- 头部知识圈的介绍 -->
		<view class="knowledgeInfoBox">
			<view class="knowledgeInfo">
				<image :src="avatar" class="knowledgeAvatar"></image>
				
				<view class="info">
					<view class="KnowledTitle">{{ knowledgeTitle }}</view>
					<view class="userAvatarBox">
						<view class="userAvatar" v-for="(item,index) in userAvatar" :key="index">
							<image :src="item" mode=""></image>
						</view>
					</view>
				</view>
			</view>
			
			<view class="shareButton">分享</view>
		</view>
		
		<!-- 任务游戏模块 -->
		<view class="taskModules">
			<view class="taskModele" v-for="(item,index) in modules" :key="index">
				<view class="text">
					<view class="taskName">{{ item.taskName }}</view>
					<view class="intro">{{ item.intro }}</view>
				</view>
				
				<image src="https://gd-hbimg.huaban.com/38f688f9a0c3d50155304859b1bd8ed6a4f608208a6-IYUhOZ_fw480webp" class="leftIcon"></image>
				
				<view class="finish">
					<image src="https://gd-hbimg.huaban.com/06e32802f0b6ae5bcd1763c55abdf8a35c38c2d422f9a-nJ08Y6_fw480webp" v-if="item.finish"></image>
				</view>
			</view>
		</view>
		
		<!-- 帖子区域 -->
		<view class="postArea">
			<view class="post" v-for="(post,index) in postList" :key="post.postId">
				<view class="userInfo">
					<image :src="post.postUser.avatar" class="userAvatar"></image>
					<view class="userName">{{ post.postUser.userName }}</view>
				</view>
				
				<view class="postContent">
					<view class="postTitle">{{ post.title }}</view>
					
					<view class="postChatText" v-if="post.type==='chat'">
						<view class="AiChatLists">
							<view class="chatBox" v-for="(item, index) in post.content.AiChatLists" :key="item.chatId">
								<view class="AiChatUser" v-if="item.chatType === 'AiChat'">
									<view class="avatar">
										<image src="https://gd-hbimg.huaban.com/a20371a173ff30590027813fe2756b631e7dab7b85517-d9DraL_fw480webp" mode="scaleToFill"></image>
									</view>
									
									<view class="AiChat_Init_Text" v-html="item.content"></view>
								</view>
								
								<view class="MyChatUser" v-if="item.chatType === 'MyChat'">
									<view class="AiChat_Init_Text" v-html="item.content"></view>
									
									<view class="avatar">
										<image :src="post.postUser.avatar" mode="scaleToFill"></image>
									</view>
								</view>
							</view>
						</view>
					</view>
					
					
					<view class="postNormalText" v-if="post.type==='normal'">
						<view class="text" v-if="post.content.Images.length === 0">
							{{ filterText(post.content.text) }}
						</view>
						<view class="Images" v-if="post.content.Images.length > 0">
							<image :src="post.content.Images[0]" mode="aspectFill"></image>
						</view>
					</view>
					
					<view class="threeButtons">
						<view class="postButton">
							<image src="https://gd-hbimg.huaban.com/758c7eb953415f3517a693044b1b40a92980f0163202-g2U53n_fw480webp" mode=""></image>
						</view>
						<view class="postButton">
							<image src="https://gd-hbimg.huaban.com/f333f1a16101326e053fbeb18f72fc39c45a324d261c-8JQzxC_fw480webp" mode=""></image>
						</view>
						<view class="postButton">
							<image src="https://gd-hbimg.huaban.com/a3ece840c4c518b93d78d467be15ff35910d3d152d73-ZSBSdW_fw480webp" mode=""></image>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import knowledge_post from '../../api/konwledge_post/knowledge_post.js';
	export default {
		data() {
			return {
				title: '知识圈',
				knowledge_circle_id: null,
				knowledgeTitle: null,
				avatar: null,
				postList: [],
				userAvatar: [
					'https://gd-hbimg.huaban.com/72eb5b8711b0c29671a114361b7cdb9dac49b06b36fa8e-mNtc6G_fw480webp',
					'https://gd-hbimg.huaban.com/65c849541f98efb6fb2d67c7ed2f64296572c158f740-35OvXt_fw480webp',
					'https://gd-hbimg.huaban.com/0c631b412b03664830df9b671a5e04ba8e31851a26d45-E1GAd0_fw480webp',
					'https://gd-hbimg.huaban.com/568596a661d0b580c4259ca5303d1ba5c35947d619442-LB7XdX_fw480webp',
					'https://gd-hbimg.huaban.com/0b2e70103c28b516c49c8edf522586afd852723b1b4890-ty529U_fw480webp',
					'https://gd-hbimg.huaban.com/8c8e703fcf107d0c6f233d1e7e4a715a3ab64bf947e27-1Gxla2_fw480webp'
				],
				modules: [
					{
						taskName: '精选学习笔记',
						intro: '干活大全',
						finish: false
					},
					{
						taskName: '任务打卡挑战',
						intro: '4个进行中',
						finish: true
					},
					{
						taskName: '今日一题',
						intro: '3个进行中',
						finish: false
					}
				]
			}
		},
		methods: {
			filterText(text){
				// 判断字符串长度，并进行截取
				return text.trim().length > 70 ? text.trim().substring(0, 70) + "......" : text.trim();
			}
		},
		onLoad(params) {
			this.knowledge_circle_id = params.knowledge_circle_id
			
			console.log(knowledge_post)
			let konwledgeList = knowledge_post.knowledge_post_list
			konwledgeList.forEach(item => {
				if (item.knowledge_circle_id == this.knowledge_circle_id) {
					this.knowledgeTitle = item.title
					this.avatar = item.avatar
					this.postList = item.posts
					console.log(item)
				}
			})
		}
	}
</script>

<style lang="less" scoped>
	.main{
		background-image: url('https://gd-hbimg.huaban.com/68bb9dee1eed7f34673120d61b18a29d88adcb83713c9-hDYMPo_fw480webp');
		background-size: 100% 100%;
		.knowledgeInfoBox{
			width: 100%;
			height: 170rpx;
			background-color: #a49c9c75;
			display: flex;
			justify-content: space-around;
			align-items: center;
			padding: 0 20rpx;
			box-sizing: border-box;
			
			.knowledgeInfo{
				width: 55%;
				display: flex;
				align-items: center;
				
				image{
					width: 115rpx;
					height: 115rpx;
					border-radius: 10px;
					background-color: #000000;
				}
				
				.info{
					color: #FFFFFF;
					margin-left: 20rpx;
					
					.KnowledTitle{
						font-size: 40rpx;
						font-weight: bold;
						margin-bottom: 16rpx;
					}
					
					.userAvatarBox{
						display: flex;
						
						.userAvatar{
							width: 42rpx;
							height: 42rpx;
							border-radius: 50%;
							background-color: #000000;
							margin-left: -6rpx;
							
							image{
								width: 100%;
								height: 100%;
								border-radius: 50%;
							}
						}
					}
				}
			}
			
			.shareButton{
				width: 125rpx;
				height: 53rpx;
				background-color: #ffffff;
				color: #000000;
				font-size: 30rpx;
				text-align: center;
				line-height: 50rpx;
				border-radius: 50px;
			}
		}
		
		.taskModules{
			width: 100%;
			height: 220rpx;
			display: flex;
			justify-content: space-around;
			align-items: center;
			padding: 20rpx 15px;
			box-sizing: border-box;
			
			.taskModele{
				width: 30%;
				height: 90%;
				display: flex;
				border-radius: 10px;
				background-color: #514f5c;
				padding: 18rpx 0rpx 10rpx 12rpx;
				z-index: 1;
				position: relative;
				
				image{
					width: 20rpx;
					height: 20rpx;
					margin-top: 10rpx;
					margin-left: 8rpx;
					z-index: 1;
				}
				
				.text{
					.taskName{
						font-size: 13.5px;
						color: #ffffff;
						margin-bottom: 7rpx;
					}
					.intro{
						font-size: 12px;
						color: #aaa9b2;
					}
					z-index: 1;
				}
				
				.finish{
					width: 65rpx;
					height: 65rpx;
					background-color: #2d303b;
					border-radius: 10px;
					position: absolute;
					bottom: 0;
					right: 0;
					z-index: 999;
					image{
						width: 88%;
						height: 88%;
						margin-top: 8rpx;
						margin-left: 7rpx;
					}
				}
			}
		}
		
		.postArea{
			width: 100%;
			margin-top: 20rpx;
			
			.post{
				color: #FFFFFF;
				width: 88%;
				margin: auto;
				padding: 20rpx;
				box-sizing: border-box;
				display: flex;
				flex-direction: column;
				justify-content: center;
				
				.userInfo{
					display: flex;
					align-items: center;
					
					.userAvatar{
						width: 85rpx;
						height: 85rpx;
						border-radius: 50%;
						background-color: #000000;
					}
					
					.userName{
						margin-left: 20rpx;
						font-size: 16px;
					}
				}
				
				.postContent{
					margin-top: 20rpx;
					
					.postTitle{
						font-size: 15px;
						padding-left: 30rpx;
					}
					
					.postNormalText{
						height: 215rpx;
						width: 100%;
						margin-top: 20rpx;
						margin-bottom: 30rpx;
						border-radius: 10px;
						background-color: rgba(174, 215, 224, 1);
						color: #000000;
						.text{
							padding: 35rpx;
							font-size: 14px;
							overflow: hidden;
							text-indent: 2rem;
						}
						.Images{
							width: 100%;
							height: 100%;
							overflow: hidden;
							image{
								width: 100%;
								height: 100%;
								border-radius: 10px;
							}
						}
					}
					.postChatText{
						height: 215rpx;
						width: 100%;
						margin-top: 20rpx;
						margin-bottom: 30rpx;
						border-radius: 10px;
						border: 1px solid #ffffff;
						.AiChatLists{
							padding: 10px;
							box-sizing: border-box;
							overflow: hidden;
							.chatBox{
								color: #fff;
								overflow: hidden;
								.AiChatUser{
									margin: auto;
									width: 100%;
									display: flex;
									margin-bottom: 15upx;
									justify-content: start;
									.avatar{
										width: 50upx;
										height: 50upx;
										image{
											width: 100%;
											height: 100%;
											border-radius: 50%;
											background-color: #a6afb2c2;
										}
										margin-right: 20upx;
										border-radius: 50%;
									}
									
									.AiChat_Init_Text{
										max-width: 66%;
										max-height: 120rpx;
										background-color: #a6afb2c2;
										border-radius: 20px;
										font-size: 12px;
										padding: 15rpx;
										box-sizing: border-box;
										overflow: hidden;
									}
								}
								.MyChatUser{
									margin: auto;
									width: 100%;
									display: flex;
									justify-content: flex-end;
									margin-bottom: 15upx;
									.avatar{
										width: 50upx;
										height: 50upx;
										image{
											width: 100%;
											height: 100%;
											border-radius: 50%;
											background-color: #a6afb2c2;
										}
										margin-left: 20upx;
										border-radius: 50%;
									}
									
									.AiChat_Init_Text{
										max-width: 66%;
										background-color: #a6afb2c2;
										border-radius: 20px;
										font-size: 12px;
										padding: 15rpx;
										box-sizing: border-box;
									}
								}
							}
						}
					}
					
					.threeButtons{
						display: flex;
						justify-content: space-between;
						margin-top: 20rpx;
						padding-left: 25rpx;
						padding-right: 25rpx;
						margin-bottom: 20rpx;
						
						.postButton{
							width: 50rpx;
							height: 50rpx;
							border-radius: 50%;
							margin-right: 20rpx;
							
							image{
								width: 100%;
								height: 100%;
							}
						}
					}
				}
			}
		}
	}
	
</style>
